//
//  ZHShouYeViewController.m
//  ZhanHui
//
//  Created by 彭超 on 16/5/12.
//  Copyright © 2016年 彭超. All rights reserved.
//

#import "ZHShouYeViewController.h"
#import "ZHFenLeiTableViewController.h"

#import "ZHShouYeTableViewCell.h"

@interface ZHShouYeViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchResultsUpdating,UISearchControllerDelegate,UISearchBarDelegate>

@property (nonatomic,strong) UISearchController*searchController;
@property (nonatomic,strong) UITableView*tableView;
@property (nonatomic,strong) NSMutableArray*shouyedataSource;

@end

@implementation ZHShouYeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createTableView];
    [self createSearchController];
    [self createNavigationItem];
    
}

-(NSMutableArray*)dataSource
{
    if (_shouyedataSource==nil) {
        _shouyedataSource=[NSMutableArray array];
    }
    return _shouyedataSource;
}

-(void)createNavigationItem
{
    UIButton*bt=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    [bt addTarget:self action:@selector(clickbutton:) forControlEvents:UIControlEventTouchUpInside];
    [bt setImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:bt];
}

-(void)clickbutton:(UIButton*)button
{
    ZHFenLeiTableViewController*flvc=[[ZHFenLeiTableViewController alloc]init];
    [self.navigationController pushViewController:flvc animated:YES];
}

-(void)createTableView
{
    _tableView=[[UITableView alloc]initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    
    [self.view addSubview:_tableView];
}

-(void)createSearchController
{
    self.searchController=[[UISearchController alloc]initWithSearchResultsController:self];
    self.tableView.tableHeaderView=self.searchController.searchBar;
    self.searchController.searchResultsUpdater=self;
    self.searchController.delegate=self;
    self.searchController.searchBar.delegate=self;
    self.searchController.searchBar.placeholder=@"搜索";
    self.definesPresentationContext=YES;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZHShouYeTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell==nil) {
        cell=[[ZHShouYeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 150;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 180;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
